package com.situ.science.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.science.mapper.LogMapper;
import com.situ.science.pojo.Contest;
import com.situ.science.pojo.Logs;
import com.situ.science.pojo.query.LogsQuery;
import com.situ.science.service.ILogService;
import com.situ.science.utils.PageRusults;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LogServiceImpl implements ILogService {

    @Autowired
    private LogMapper logMapper;
    @Override
    public void add(Logs logs) {
        logMapper.add(logs);
    }

    @Override
    public List<Logs> list() {
        return List.of();
    }
    @Override
    public PageRusults selectByPage(LogsQuery logQuery) {
        int limit = logQuery.getLimit()!= null? logQuery.getLimit() : 10; // 设置默认值为 10，如果 limit 为 null
        int page = logQuery.getPage()!= null? logQuery.getPage() : 1;

        PageHelper.startPage(page, limit);
        //1.查询当前页列表
        List<Logs> logsList = logMapper.selectByPage(logQuery);
        //2.用一个小插件查询总数量
        PageInfo pageInfo = new PageInfo(logsList);
        int total = (int) pageInfo.getTotal();
        return new PageRusults(0,"",total,logsList);
    }
}
